(function($){if(undefined===$.wysiwyg){throw "wysiwyg.image.js depends on $.wysiwyg";} if(!$.wysiwyg.controls){$.wysiwyg.controls={};} $.wysiwyg.controls.image={init:function(Wysiwyg){var self=this,elements,dialog,formImageHtml,dialogReplacements,key,translation,img={alt:"",self:Wysiwyg.dom.getElement("img"),src:"http://",title:""};dialogReplacements={legend:"Insert Image",preview:"Preview",url:"URL",title:"Title",description:"Description",width:"Width",height:"Height",original:"Original W x H",float:"Float",floatNone:"None",floatLeft:"Left",floatRight:"Right",submit:"Insert Image",reset:"Cancel"};formImageHtml='
{legend}'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ' '+ '
';for(key in dialogReplacements){if($.wysiwyg.i18n){translation=$.wysiwyg.i18n.t(dialogReplacements[key],"dialogs.image");if(translation===dialogReplacements[key]){translation=$.wysiwyg.i18n.t(dialogReplacements[key],"dialogs");} dialogReplacements[key]=translation;} formImageHtml=formImageHtml.replace("{"+key+"}",dialogReplacements[key]);} if(img.self){img.src=img.self.src?img.self.src:"";img.alt=img.self.alt?img.self.alt:"";img.title=img.self.title?img.self.title:"";img.width=img.self.width?img.self.width:"";img.height=img.self.height?img.self.height:"";} if(true){var defaultValue="http://";var imageUrl=prompt("Insert image",defaultValue);if(imageUrl&&imageUrl!==""&&imageUrl!==defaultValue){Wysiwyg.insertHtml('');}}else if($.modal){elements=$(formImageHtml);elements=self.makeForm(elements,img);$.modal(elements,{onShow:function(dialog){$("input:submit",dialog.data).click(function(e){self.processInsert(dialog.container,Wysiwyg,img);$.modal.close();return false;});$("input:reset",dialog.data).click(function(e){$.modal.close();return false;});$("fieldset",dialog.data).click(function(e){e.stopPropagation();});},maxWidth:Wysiwyg.defaults.formWidth,maxHeight:Wysiwyg.defaults.formHeight,overlayClose:true});}else if($.fn.dialog){elements=$(formImageHtml);elements=self.makeForm(elements,img);dialog=elements.appendTo("body");dialog.dialog({modal:true,open:function(ev,ui){$("input:submit",dialog).click(function(e){self.processInsert(dialog.container,Wysiwyg,img);$(dialog).dialog("close");return false;});$("input:reset",dialog).click(function(e){$(dialog).dialog("close");return false;});$('fieldset',dialog).click(function(e){e.stopPropagation();});},close:function(ev,ui){dialog.dialog("destroy");}});}else{if($.browser.msie){Wysiwyg.ui.focus();Wysiwyg.editorDoc.execCommand("insertImage",true,null);}else{elements=$("
").css({"position":"fixed","z-index":2000,"left":"50%","top":"50%","background":"rgb(0, 0, 0)","margin-top":-1*Math.round(Wysiwyg.defaults.formHeight/2),"margin-left":-1*Math.round(Wysiwyg.defaults.formWidth/2)}).html(formImageHtml);elements=self.makeForm(elements,img);$("input:submit",elements).click(function(event){self.processInsert(elements,Wysiwyg,img);$(elements).remove();return false;});$("input:reset",elements).click(function(event){if($.browser.msie){Wysiwyg.ui.returnRange();} $(elements).remove();return false;});$("body").append(elements);elements.click(function(e){e.stopPropagation();});}} $(Wysiwyg.editorDoc).trigger("editorRefresh.wysiwyg");},processInsert:function(context,Wysiwyg,img){var image,url=$('input[name="src"]',context).val(),title=$('input[name="imgtitle"]',context).val(),description=$('input[name="description"]',context).val(),width=$('input[name="width"]',context).val(),height=$('input[name="height"]',context).val(),styleFloat=$('select[name="float"]',context).val(),style=[],found,baseUrl;if(Wysiwyg.options.controlImage.forceRelativeUrls){baseUrl=window.location.protocol+"//"+window.location.hostname;if(0===url.indexOf(baseUrl)){url=url.substr(baseUrl.length);}} if(img.self){$(img.self).attr("src",url).attr("title",title).attr("alt",description).css("float",styleFloat);if(width.toString().match(/^[0-9]+(px|%)?$/)){$(img.self).css("width",width);}else{$(img.self).css("width","");} if(height.toString().match(/^[0-9]+(px|%)?$/)){$(img.self).css("height",height);}else{$(img.self).css("height","");}}else{found=width.toString().match(/^[0-9]+(px|%)?$/);if(found){if(found[1]){style.push("width: "+width+";");}else{style.push("width: "+width+"px;");}} found=height.toString().match(/^[0-9]+(px|%)?$/);if(found){if(found[1]){style.push("height: "+height+";");}else{style.push("height: "+height+"px;");}} if(styleFloat.length>0){style.push("float: "+styleFloat+";");} if(style.length>0){style=' style="'+style.join(" ")+'"';} image=""+description+"";Wysiwyg.insertHtml(image);}},makeForm:function(form,img){form.find("input[name=src]").val(img.src);form.find("input[name=imgtitle]").val(img.title);form.find("input[name=description]").val(img.alt);form.find('input[name="width"]').val(img.width);form.find('input[name="height"]').val(img.height);form.find('img').attr("src",img.src);form.find('img').bind("load",function(){if(form.find('img').attr("naturalWidth")){form.find('input[name="naturalWidth"]').val(form.find('img').attr("naturalWidth"));form.find('input[name="naturalHeight"]').val(form.find('img').attr("naturalHeight"));}});form.find("input[name=src]").bind("change",function(){form.find('img').attr("src",this.value);});return form;}};$.wysiwyg.insertImage=function(object,url,attributes){return object.each(function(){var self=$(this).data("wysiwyg"),image,attribute;if(!self){return this;} if(!url||url.length===0){return this;} if($.browser.msie){self.ui.focus();} if(attributes){self.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");image=self.getElementByAttributeValue("img","src","#jwysiwyg#");if(image){image.src=url;for(attribute in attributes){if(attributes.hasOwnProperty(attribute)){image.setAttribute(attribute,attributes[attribute]);}}}}else{self.editorDoc.execCommand("insertImage",false,url);} $(self.editorDoc).trigger("editorRefresh.wysiwyg");return this;});};})(jQuery);